﻿using System;
using GameEngine.Model;
using GameEngine.Model.Data;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using GameEngine.View.Components;

namespace GameEngine.Controller
{
    public class AddThingToWorldCommand<MyIdType, MyBaseUIElementType> : SimpleCommand
        where MyIdType : IComparable<MyIdType>
    {
        override public void Execute(INotification notification)
        {
            var thing = notification.Body as IThingVO<MyIdType>;
            var worldId = notification.Type;

            foreach (var lvl in ModelFacade<MyIdType>.Instance.Game.Levels.Values) {
                foreach (var world in lvl.Worlds) { 
                    if(world.Id.Value.Equals(worldId)){

                        var thingDataProxy = ApplicationFacadeHelper<MyIdType>.CreateThing(thing, world.Id);

                        var worldDataProxy = ModelFacade<MyIdType>.Helper.GetWorldDataProxy(world);
                        worldDataProxy.AddItem(thingDataProxy);
                        return;
                    }
                }
            }
        }
    }
}
